﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Giohang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        XuLyGioHang xl = Session["giohang"] as XuLyGioHang ;
        if (!IsPostBack)
        {
            if (Session["user"] == null)
                Response.Redirect("~/DangNhap.aspx");
            if (Request["MaSP"] != null)
            {
                xl.ThemSanPham(Convert.ToInt32(Request["MaSP"]));
                Response.Redirect("~/Giohang.aspx");
            }
            GridView1.DataSource = xl.dssp;
            GridView1.DataBind();
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
         if (e.CommandName == "NutXoa")
        {
            int dong = Convert.ToInt32(e.CommandArgument);
            int masanpham = Convert.ToInt32(GridView1.Rows[dong].Cells[0].Text);
            XuLyGioHang xl = Session["giohang"] as XuLyGioHang;
            xl.XoaSanPham(masanpham);
            Response.Redirect("~/Giohang.aspx");
        }
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            int masanpham = Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
            int sl = Convert.ToInt32(Request.Form[6 + i]);////////////////////////////////////////////////////////

            XuLyGioHang xl = Session["giohang"] as XuLyGioHang;
            xl.CapNhatSoLuong(masanpham, sl);
        }
        Response.Redirect("~/Giohang.aspx");
    }
    protected void btnXoa_Click(object sender, EventArgs e)
    {
        if (GridView1.Rows.Count > 0)
        {
            XuLyGioHang xl = Session["giohang"] as XuLyGioHang;
            xl.XoaTatCa();
        }
        Response.Redirect("~/GioHang.aspx");

    }
    protected void btnMuaThem_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/defaut.aspx");
    }
    protected void btnThanhToan_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/ThanhToan.aspx");
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}